//
//  LZGroupOrderCollectionViewCell.m
//  laziz_Merchant
//
//  Created by ZhaoDongBo on 2016/12/27.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZGroupOrderCollectionViewCell.h"
#import "Masonry.h"
#import "LZGroupItemModel.h"

@interface LZGroupOrderCollectionViewCell()

@property (nonatomic, strong) UILabel * titleLabel;
@property (nonatomic, strong) UIImageView * markImageView;

@end

@implementation LZGroupOrderCollectionViewCell

-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.layer.cornerRadius = 4.0;
        
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.backgroundColor = [UIColor clearColor];
        self.titleLabel.font = [UIFont systemFontOfSize:15.];
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        self.titleLabel.textColor = UIColorFromRGB(0x333333, 1);
        [self addSubview:self.titleLabel];
        
        self.markImageView = [[UIImageView alloc] init];
        if ([[LZLanguageManager shareInstance] getLanguageType] == LanguageType_Ar){
            self.markImageView.image = [UIImage imageNamed:@"lz_selectgroup_mark_ar"];
        } else {
            self.markImageView.image = [UIImage imageNamed:@"lz_selectgroup_mark_en"];
        }
        
        self.markImageView.hidden = YES;
        [self addSubview:self.markImageView];
        
        const int padding = 0; // 间距
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(padding);
            make.top.mas_equalTo(padding);
            make.bottom.mas_equalTo(-padding);
            make.trailing.mas_equalTo(-padding);
        }];
        
        [self.markImageView makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(0);
            make.trailing.mas_equalTo(0);
            make.size.mas_equalTo(CGSizeMake(18, 18));
        }];
    }
    return self;
}

- (void)setModel:(LZGroupItemModel *)model {
    _model = model;
    self.titleLabel.text = model.foodName;
    if(model.isSelect) {
        self.backgroundColor = UIColorFromRGB(0xffffff, 1);
        self.layer.borderWidth = 0.5;
        self.layer.borderColor = UIColorFromRGB(0x33a928, 1).CGColor;
        self.markImageView.hidden = NO;
    }
    else {
        self.backgroundColor = UIColorFromRGB(0xeeeeee, 1);
        self.layer.borderWidth = 0;
        self.layer.borderColor = [UIColor clearColor].CGColor;
        self.markImageView.hidden = YES;
    }
}

+ (CGSize)getCellSizeWithText:(NSString*)text
{
    CGSize size;
    NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:15.]};
    CGRect titleRect = [text boundingRectWithSize:CGSizeMake(SCREEN_WIDTH, MAXFLOAT)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:attributes
                                          context:nil];
    titleRect.size.height = 40;
    titleRect.size.width += 30;
    size = titleRect.size;
    return size;
}

@end
